/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.view;

import br.com.documentar.controller.CategoriaArvoreController;
import br.com.documentar.controller.OpcaoDocumentoController;
import br.com.documentar.controller.ProdutoController;
import br.com.documentar.controller.TelaController;
import br.com.documentar.controller.VersaoController;
import br.com.documentar.interfacee.InterfaceView;
import br.com.documentar.model.CategoriaArvoreModel;
import br.com.documentar.model.DocumentarModel;
import br.com.documentar.model.OpcaoDocumentoModel;
import br.com.documentar.model.ProdutoModel;
import br.com.documentar.model.TelaModel;
import br.com.documentar.model.VersaoModel;
import br.com.documentar.util.UtilitariosCampos;
import br.com.documentar.util.setFiltroCampo;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

/**
 *
 * @author Santos
 */
public class DocumentarView extends javax.swing.JFrame implements InterfaceView<br.com.documentar.model.DocumentarModel> {

    private br.com.documentar.controller.DocumentarController control = new br.com.documentar.controller.DocumentarController();
    private br.com.documentar.model.DocumentarModel model = control.getModel();

    /**
     * Creates new form DocumentarView
     */
    public DocumentarView() {
        initComponents();
        Start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabbedPaneManutencao = new javax.swing.JTabbedPane();
        panelConsulta = new javax.swing.JPanel();
        jLabelNome = new javax.swing.JLabel();
        textFieldConsultar = new javax.swing.JTextField();
        jScrollPaneTable = new javax.swing.JScrollPane();
        jTableConsulta = new javax.swing.JTable();
        panelAbaACadastro = new javax.swing.JPanel();
        jScrollPaneManutencaoClienteA = new javax.swing.JScrollPane();
        jPanelManutencaoACadastro = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        comboBoxCategoria = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        comboBoxVersao = new javax.swing.JComboBox();
        textFieldAba = new javax.swing.JTextField();
        textFieldPosicao = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        textFieldCampo = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textAreaFuncaoParametro = new javax.swing.JTextArea();
        jLabel15 = new javax.swing.JLabel();
        textFieldCodigo = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        comboBoxProduto = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        comboBoxTela = new javax.swing.JComboBox();
        panelAbaBCadastro = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        textAreaExemplo = new javax.swing.JTextArea();
        jLabel7 = new javax.swing.JLabel();
        textFieldImagemTela = new javax.swing.JTextField();
        textFieldLinkVideo = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        textFieldAnexo = new javax.swing.JTextField();
        comboBoxAtivo = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jButtonOpcaoDocumento = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableOpcaoDocumento = new javax.swing.JTable();
        jButtonAtualizar = new javax.swing.JButton();
        panelAbaCCadastro = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        textAreaConsultaSQL = new javax.swing.JTextArea();
        panelAbaRelatorio = new javax.swing.JPanel();
        toolBarManutencao = new javax.swing.JToolBar();
        buttonConsultar = new javax.swing.JButton();
        buttonNovo = new javax.swing.JButton();
        buttonEditar = new javax.swing.JButton();
        buttonExcluir = new javax.swing.JButton();
        buttonCancelar = new javax.swing.JButton();
        buttonGravar = new javax.swing.JButton();
        buttonRelatorio = new javax.swing.JButton();
        buttonAnterior = new javax.swing.JButton();
        buttonProximo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastrar Documento");

        jLabelNome.setText("Pesquisar:");

        jTableConsulta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableConsulta.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jTableConsulta.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTableConsulta.getTableHeader().setReorderingAllowed(false);
        jScrollPaneTable.setViewportView(jTableConsulta);

        javax.swing.GroupLayout panelConsultaLayout = new javax.swing.GroupLayout(panelConsulta);
        panelConsulta.setLayout(panelConsultaLayout);
        panelConsultaLayout.setHorizontalGroup(
            panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConsultaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelNome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textFieldConsultar, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jScrollPaneTable, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
        );
        panelConsultaLayout.setVerticalGroup(
            panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConsultaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNome)
                    .addComponent(textFieldConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPaneTable, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE))
        );

        tabbedPaneManutencao.addTab("Consulta", panelConsulta);

        jLabel1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel1.setText("Versão:");

        jLabel10.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel10.setText("Categoria:");

        comboBoxCategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER" }));

        jLabel4.setText("Aba:");

        jLabel5.setText("Posição:");

        comboBoxVersao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER" }));

        jLabel11.setText("Campo:");

        jLabel12.setText("Função:");

        textAreaFuncaoParametro.setColumns(20);
        textAreaFuncaoParametro.setRows(5);
        jScrollPane1.setViewportView(textAreaFuncaoParametro);

        jLabel15.setText("Código:");

        jLabel16.setText("Produto:");

        comboBoxProduto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER" }));

        jLabel14.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel14.setText("Tela:");

        comboBoxTela.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER" }));

        javax.swing.GroupLayout jPanelManutencaoACadastroLayout = new javax.swing.GroupLayout(jPanelManutencaoACadastro);
        jPanelManutencaoACadastro.setLayout(jPanelManutencaoACadastroLayout);
        jPanelManutencaoACadastroLayout.setHorizontalGroup(
            jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelManutencaoACadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel1)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel15)
                    .addComponent(jLabel16)
                    .addComponent(jLabel14))
                .addGap(18, 18, 18)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelManutencaoACadastroLayout.createSequentialGroup()
                        .addComponent(textFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(comboBoxProduto, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(comboBoxVersao, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(comboBoxCategoria, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(textFieldAba)
                    .addComponent(textFieldPosicao)
                    .addComponent(textFieldCampo)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE)
                    .addComponent(comboBoxTela, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelManutencaoACadastroLayout.setVerticalGroup(
            jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelManutencaoACadastroLayout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(textFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(comboBoxProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(comboBoxVersao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(comboBoxCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(comboBoxTela, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(textFieldAba, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(textFieldPosicao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(textFieldCampo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelManutencaoACadastroLayout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE))
                .addContainerGap())
        );

        jScrollPaneManutencaoClienteA.setViewportView(jPanelManutencaoACadastro);

        javax.swing.GroupLayout panelAbaACadastroLayout = new javax.swing.GroupLayout(panelAbaACadastro);
        panelAbaACadastro.setLayout(panelAbaACadastroLayout);
        panelAbaACadastroLayout.setHorizontalGroup(
            panelAbaACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneManutencaoClienteA)
        );
        panelAbaACadastroLayout.setVerticalGroup(
            panelAbaACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneManutencaoClienteA)
        );

        tabbedPaneManutencao.addTab("Pagina A", panelAbaACadastro);

        jLabel6.setText("Exemplo:");

        textAreaExemplo.setColumns(20);
        textAreaExemplo.setRows(5);
        jScrollPane3.setViewportView(textAreaExemplo);

        jLabel7.setText("Imagem:");

        jLabel13.setText("Linik Vídeo:");

        jLabel2.setText("Ativo:");

        jLabel8.setText("Anexo:");

        comboBoxAtivo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER", "S - Sim", "N - Não" }));

        jLabel3.setText("Parâmetros:");

        jButtonOpcaoDocumento.setText("Editar");
        jButtonOpcaoDocumento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOpcaoDocumentoActionPerformed(evt);
            }
        });

        jTableOpcaoDocumento.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableOpcaoDocumento.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jTableOpcaoDocumento.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTableOpcaoDocumento.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(jTableOpcaoDocumento);

        jButtonAtualizar.setText("Atualizar");
        jButtonAtualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAtualizarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelAbaBCadastroLayout = new javax.swing.GroupLayout(panelAbaBCadastro);
        panelAbaBCadastro.setLayout(panelAbaBCadastroLayout);
        panelAbaBCadastroLayout.setHorizontalGroup(
            panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAbaBCadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelAbaBCadastroLayout.createSequentialGroup()
                        .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel13)
                            .addComponent(jLabel2)
                            .addComponent(jLabel8)
                            .addComponent(jLabel3))
                        .addGap(16, 16, 16)
                        .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
                            .addComponent(textFieldImagemTela)
                            .addComponent(textFieldAnexo)
                            .addComponent(textFieldLinkVideo)
                            .addGroup(panelAbaBCadastroLayout.createSequentialGroup()
                                .addComponent(comboBoxAtivo, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelAbaBCadastroLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButtonAtualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonOpcaoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        panelAbaBCadastroLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButtonAtualizar, jButtonOpcaoDocumento});

        panelAbaBCadastroLayout.setVerticalGroup(
            panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAbaBCadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(textFieldImagemTela, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(textFieldAnexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldLinkVideo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxAtivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelAbaBCadastroLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(0, 110, Short.MAX_VALUE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonOpcaoDocumento)
                    .addComponent(jButtonAtualizar)))
        );

        tabbedPaneManutencao.addTab("Pagina B", panelAbaBCadastro);

        jLabel9.setText("Consulta SQL:");

        textAreaConsultaSQL.setColumns(20);
        textAreaConsultaSQL.setRows(5);
        jScrollPane4.setViewportView(textAreaConsultaSQL);

        javax.swing.GroupLayout panelAbaCCadastroLayout = new javax.swing.GroupLayout(panelAbaCCadastro);
        panelAbaCCadastro.setLayout(panelAbaCCadastroLayout);
        panelAbaCCadastroLayout.setHorizontalGroup(
            panelAbaCCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAbaCCadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addGap(31, 31, 31)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelAbaCCadastroLayout.setVerticalGroup(
            panelAbaCCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAbaCCadastroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelAbaCCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelAbaCCadastroLayout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE))
                .addContainerGap())
        );

        tabbedPaneManutencao.addTab("Pagina C", panelAbaCCadastro);

        javax.swing.GroupLayout panelAbaRelatorioLayout = new javax.swing.GroupLayout(panelAbaRelatorio);
        panelAbaRelatorio.setLayout(panelAbaRelatorioLayout);
        panelAbaRelatorioLayout.setHorizontalGroup(
            panelAbaRelatorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 541, Short.MAX_VALUE)
        );
        panelAbaRelatorioLayout.setVerticalGroup(
            panelAbaRelatorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 421, Short.MAX_VALUE)
        );

        tabbedPaneManutencao.addTab("Relatório", panelAbaRelatorio);

        toolBarManutencao.setFloatable(false);
        toolBarManutencao.setRollover(true);

        buttonConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_form_magnify.png"))); // NOI18N
        buttonConsultar.setMnemonic('l');
        buttonConsultar.setText("Consultar");
        buttonConsultar.setFocusable(false);
        buttonConsultar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonConsultar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonConsultarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonConsultar);

        buttonNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_add.png"))); // NOI18N
        buttonNovo.setMnemonic('N');
        buttonNovo.setText("Novo");
        buttonNovo.setFocusable(false);
        buttonNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNovoActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonNovo);

        buttonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_edit.png"))); // NOI18N
        buttonEditar.setMnemonic('E');
        buttonEditar.setText("Editar");
        buttonEditar.setFocusable(false);
        buttonEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEditarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonEditar);

        buttonExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_delete.png"))); // NOI18N
        buttonExcluir.setMnemonic('x');
        buttonExcluir.setText("Excluir");
        buttonExcluir.setFocusable(false);
        buttonExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonExcluirActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonExcluir);

        buttonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/cancel.png"))); // NOI18N
        buttonCancelar.setMnemonic('C');
        buttonCancelar.setText("Cancelar");
        buttonCancelar.setFocusable(false);
        buttonCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonCancelar);

        buttonGravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/accept.png"))); // NOI18N
        buttonGravar.setMnemonic('a');
        buttonGravar.setText("Gravar");
        buttonGravar.setFocusable(false);
        buttonGravar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonGravar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonGravarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonGravar);

        buttonRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_side_list.png"))); // NOI18N
        buttonRelatorio.setMnemonic('R');
        buttonRelatorio.setText("Relatório");
        buttonRelatorio.setFocusable(false);
        buttonRelatorio.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonRelatorio.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonRelatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRelatorioActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonRelatorio);

        buttonAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/arrow_left.png"))); // NOI18N
        buttonAnterior.setMnemonic('o');
        buttonAnterior.setText("Anterior");
        buttonAnterior.setFocusable(false);
        buttonAnterior.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonAnterior.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAnteriorActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonAnterior);

        buttonProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/arrow_right.png"))); // NOI18N
        buttonProximo.setMnemonic('m');
        buttonProximo.setText("Próximo");
        buttonProximo.setFocusable(false);
        buttonProximo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonProximo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonProximoActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonProximo);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPaneManutencao)
            .addComponent(toolBarManutencao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(toolBarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabbedPaneManutencao))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConsultarActionPerformed
        Consultar();
    }//GEN-LAST:event_buttonConsultarActionPerformed

    private void buttonNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNovoActionPerformed
        CarregarNovoDados();
    }//GEN-LAST:event_buttonNovoActionPerformed

    private void buttonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEditarActionPerformed
        CarregarEditarDados();
    }//GEN-LAST:event_buttonEditarActionPerformed

    private void buttonExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExcluirActionPerformed
        CarregarExcluirDados();
    }//GEN-LAST:event_buttonExcluirActionPerformed

    private void buttonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelarActionPerformed
        CancelarOperacao();
    }//GEN-LAST:event_buttonCancelarActionPerformed

    private void buttonGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGravarActionPerformed
        GravarDados();
    }//GEN-LAST:event_buttonGravarActionPerformed

    private void buttonRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRelatorioActionPerformed
        tabbedPaneManutencao.setSelectedIndex(2);
    }//GEN-LAST:event_buttonRelatorioActionPerformed

    private void buttonAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAnteriorActionPerformed
        ProximaAba("Anterior");
    }//GEN-LAST:event_buttonAnteriorActionPerformed

    private void buttonProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProximoActionPerformed
        ProximaAba("Proximo");
    }//GEN-LAST:event_buttonProximoActionPerformed

    private void jButtonOpcaoDocumentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOpcaoDocumentoActionPerformed
        OpcaoDocumentoView opcaoDocView = new OpcaoDocumentoView(Integer.parseInt(textFieldCodigo.getText()));
        opcaoDocView.setVisible(true);
    }//GEN-LAST:event_jButtonOpcaoDocumentoActionPerformed

    private void jButtonAtualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAtualizarActionPerformed
        OpcaoDocumentoController opcaoDocumentoControl = new OpcaoDocumentoController();
        OpcaoDocumentoModel opcaoDocModel = opcaoDocumentoControl.getModel();
        opcaoDocModel.setActionScript("porDocumento");
        opcaoDocModel.getDocumento().setCodigo(Integer.parseInt(textFieldCodigo.getText()));
        jTableOpcaoDocumento.setModel(opcaoDocumentoControl.getDadosTableModel(opcaoDocModel));
        TamanhoColunaTableOpcaoDocumento();
    }//GEN-LAST:event_jButtonAtualizarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main() {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DocumentarView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DocumentarView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DocumentarView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DocumentarView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DocumentarView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonAnterior;
    private javax.swing.JButton buttonCancelar;
    protected javax.swing.JButton buttonConsultar;
    private javax.swing.JButton buttonEditar;
    private javax.swing.JButton buttonExcluir;
    private javax.swing.JButton buttonGravar;
    private javax.swing.JButton buttonNovo;
    private javax.swing.JButton buttonProximo;
    private javax.swing.JButton buttonRelatorio;
    private javax.swing.JComboBox comboBoxAtivo;
    private javax.swing.JComboBox comboBoxCategoria;
    private javax.swing.JComboBox comboBoxProduto;
    private javax.swing.JComboBox comboBoxTela;
    private javax.swing.JComboBox comboBoxVersao;
    private javax.swing.JButton jButtonAtualizar;
    private javax.swing.JButton jButtonOpcaoDocumento;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JPanel jPanelManutencaoACadastro;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPaneManutencaoClienteA;
    private javax.swing.JScrollPane jScrollPaneTable;
    private javax.swing.JTable jTableConsulta;
    private javax.swing.JTable jTableOpcaoDocumento;
    private javax.swing.JPanel panelAbaACadastro;
    private javax.swing.JPanel panelAbaBCadastro;
    private javax.swing.JPanel panelAbaCCadastro;
    private javax.swing.JPanel panelAbaRelatorio;
    private javax.swing.JPanel panelConsulta;
    private javax.swing.JTabbedPane tabbedPaneManutencao;
    private javax.swing.JTextArea textAreaConsultaSQL;
    private javax.swing.JTextArea textAreaExemplo;
    private javax.swing.JTextArea textAreaFuncaoParametro;
    private javax.swing.JTextField textFieldAba;
    private javax.swing.JTextField textFieldAnexo;
    private javax.swing.JTextField textFieldCampo;
    private javax.swing.JTextField textFieldCodigo;
    private javax.swing.JTextField textFieldConsultar;
    private javax.swing.JTextField textFieldImagemTela;
    private javax.swing.JTextField textFieldLinkVideo;
    private javax.swing.JTextField textFieldPosicao;
    private javax.swing.JToolBar toolBarManutencao;
    // End of variables declaration//GEN-END:variables

    @Override
    public void CarregarEditarDados() {
        if (jTableConsulta.getSelectedRow() != -1) {
            model.setActionScript("U");
            textFieldCodigo.setEnabled(false);
            jButtonAtualizar.setEnabled(true);
            jButtonOpcaoDocumento.setEnabled(true);
            DocumentarModel documentarModel
                    = model.getDocumentar(
                            UtilitariosCampos.getIntegerTable(jTableConsulta, 0));

            textFieldCodigo.setText(UtilitariosCampos.getIntegerText(documentarModel.getCodigo()));
            comboBoxProduto.setSelectedItem(documentarModel.getProduto().getCodigo() + " - " + documentarModel.getProduto().getNome());
            comboBoxVersao.setSelectedItem(documentarModel.getCategoriaVersao().getVersao().getCodigo() + " - " + documentarModel.getCategoriaVersao().getVersao().getNome());

            comboBoxCategoria.setSelectedItem(documentarModel.getCategoriaVersao().getCategoria().getCodigo() + " - " + documentarModel.getCategoriaVersao().getCategoria().getNome());

            comboBoxTela.setSelectedItem(documentarModel.getCategoriaVersao().getTelaModel().getCodigo() + " - " + documentarModel.getCategoriaVersao().getTelaModel().getNome());

            textFieldAba.setText(documentarModel.getAba());
            textFieldPosicao.setText(documentarModel.getPosicao());
            textFieldCampo.setText(documentarModel.getNomeCampo());
            textAreaFuncaoParametro.setText(documentarModel.getFuncaoParamentro());
            textAreaExemplo.setText(documentarModel.getExemplo());
            textFieldAnexo.setText(documentarModel.getAnexo());
            textFieldImagemTela.setText(documentarModel.getImagemTela());
            textFieldLinkVideo.setText(documentarModel.getLinkVideo());
            UtilitariosCampos.setRespostaComboBox(comboBoxAtivo, documentarModel.getAtivo());
            textAreaConsultaSQL.setText(documentarModel.getSqlTextArea());
            OpcaoDocumentoController opcaoDocumentoControl = new OpcaoDocumentoController();
            OpcaoDocumentoModel opcaoDocModel = opcaoDocumentoControl.getModel();
            opcaoDocModel.setActionScript("porDocumento");
            opcaoDocModel.getDocumento().setCodigo(documentarModel.getCodigo());
            jTableOpcaoDocumento.setModel(opcaoDocumentoControl.getDadosTableModel(opcaoDocModel));
            TamanhoColunaTableOpcaoDocumento();
            tabbedPaneManutencao.setSelectedIndex(1);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Nenhuma linha selecionada");
        }
    }

    ItemListener comboBoxProdutoListener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (!comboBoxProduto.getSelectedItem().toString().equals("ESCOLHER")
                    && e.getStateChange() == 2) {

                VersaoController versaoControl = new VersaoController();
                VersaoModel versaoModel = versaoControl.getModel();
                versaoModel.setActionScript("porCategoriaVersao");
                versaoModel.getProduto().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxProduto));
                comboBoxVersao.setModel(versaoControl.getDadosComboBoxModel(versaoModel));
            }
        }
    };

    ItemListener comboBoxVersaoListener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (!comboBoxVersao.getSelectedItem().toString().equals("ESCOLHER")
                    && e.getStateChange() == 2) {
                CategoriaArvoreController categoriaControl = new CategoriaArvoreController();
                CategoriaArvoreModel categoriaModel = categoriaControl.getModel();
                categoriaModel.getModelComboBox().removeAllElements();
                categoriaModel.getModelComboBox().addElement("ESCOLHER");
                categoriaModel.setActionScript("porProdutoVersao");
                categoriaModel.getProduto().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxProduto));
                categoriaModel.getVersaoModel().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxVersao));
                comboBoxCategoria.setModel(categoriaControl.getDadosComboBoxModel(categoriaModel));
            }
        }
    };

    ItemListener comboBoxCategoriaListener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (!comboBoxCategoria.getSelectedItem().toString().equals("ESCOLHER")
                    && e.getStateChange() == 2) {

                TelaController telaControl = new TelaController();
                TelaModel telaModel = telaControl.getModel();
                telaModel.getModelComboBox().removeAllElements();
                telaModel.getModelComboBox().addElement("ESCOLHER");
                telaModel.setActionScript("porProdutoCategoriaVersao");
                telaModel.getProdutoModel().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxProduto));
                telaModel.getCategoriaModel().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxCategoria));
                telaModel.getVersaoModel().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxVersao));

                comboBoxTela.setModel(telaControl.getDadosComboBoxModel(telaModel));
            }
        }
    };

    @Override
    public void CarregarNovoDados() {
        model.setActionScript("I");
        textFieldCodigo.setEnabled(false);
        jButtonAtualizar.setEnabled(false);
        jButtonOpcaoDocumento.setEnabled(false);
        tabbedPaneManutencao.setSelectedIndex(1);
        comboBoxProduto.requestFocus();
    }

    @Override
    public void CarregarExcluirDados() {
        if (jTableConsulta.getSelectedRow() != -1) {
            DocumentarModel documentarModel = model.getDocumentar(
                    UtilitariosCampos.getIntegerTable(jTableConsulta, 0));
            documentarModel.setActionScript("D");
            control.setDados(documentarModel);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Nenhuma linha selecionada");
        }
        Consultar();
    }

    @Override
    public void CancelarOperacao() {
        LimparCampos();
        Consultar();
    }

    @Override
    public void CarregarVariaveis() {
        model.setCodigo(UtilitariosCampos.getIntegerText(textFieldCodigo));
        model.getCategoriaVersao().getVersao().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxVersao));
        model.getCategoriaVersao().getCategoria().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxCategoria));
        model.getCategoriaVersao().getTelaModel().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxTela));
        model.setAba(textFieldAba.getText());
        model.setPosicao(textFieldPosicao.getText());
        model.setNomeCampo(textFieldCampo.getText());
        model.setFuncaoParamentro(textAreaFuncaoParametro.getText());
        model.setExemplo(textAreaExemplo.getText());
        model.setImagemTela(textFieldImagemTela.getText());
        model.setAnexo(textFieldAnexo.getText().toString());
        model.setLinkVideo(textFieldLinkVideo.getText());
        model.setAtivo(UtilitariosCampos.getRespostaComboBox(comboBoxAtivo));
        model.setSql(textAreaConsultaSQL.getText());
    }

    @Override
    public void GravarDados() {
        if (model.getActionScript().equals("I") || model.getActionScript().equals("U")) {
            if (ValidaCampos()) {
                CarregarVariaveis();
                if (model.getActionScript().equals("I") && model.getDocumentar(model.getCodigo()) != null) {
                    JOptionPane.showMessageDialog(panelConsulta, "Item já cadastrado na base de dados.");
                } else {
                    if (control.setDados(model)) {
                        Consultar();
                        LimparCampos();
                    }
                }
            }
        } else {
            JOptionPane.showMessageDialog(panelConsulta, "Você deve escolher uma ação clicando no botão Novo ou Editar.");
        }
    }

    @Override
    public void LimparCampos() {
        UtilitariosCampos.getLimpezaCampos(tabbedPaneManutencao);
    }

    @Override
    public void ProximaAba(String Movimento) {
        int a = tabbedPaneManutencao.getSelectedIndex();
        int quantidadeAba = tabbedPaneManutencao.getTabCount() - 1;
        switch (Movimento) {
            case "Anterior":
                if (a != 0) {
                    tabbedPaneManutencao.setSelectedIndex(a - 1);
                }
                break;
            case "Proximo":
                if (a != quantidadeAba) {
                    tabbedPaneManutencao.setSelectedIndex(a + 1);
                }
                break;
        }
    }

    @Override
    public void TamanhoColunaTable() {
        int posicao = 0;
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 70);//codigo
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 200);//produto
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 100);//versao
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 650);//categoria
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 650);//tela
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 200);//aba
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 70);//posicao
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 270);//nome do campo
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 270);//função parâmetro
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 270);//exemplo
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 270);//imagem da tela
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 270);//anexo
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 270);//link do video
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 270);//sql
        UtilitariosCampos.setTamanhoColunaTable(jTableConsulta, posicao++, 100);//ativo
    }

    private void TamanhoColunaTableOpcaoDocumento() {
        int posicao = 0;
        UtilitariosCampos.setTamanhoColunaTable(jTableOpcaoDocumento, posicao++, 70);//codigo
        UtilitariosCampos.setTamanhoColunaTable(jTableOpcaoDocumento, posicao++, 120);//documento
        UtilitariosCampos.setTamanhoColunaTable(jTableOpcaoDocumento, posicao++, 100);//valor
        UtilitariosCampos.setTamanhoColunaTable(jTableOpcaoDocumento, posicao++, 650);//comportamento
        UtilitariosCampos.setTamanhoColunaTable(jTableOpcaoDocumento, posicao++, 650);//anexo
    }

    @Override
    public void Consultar() {
        model.setActionScript("C");
        jTableConsulta.setModel(control.getDadosTableModel(model));
        tabbedPaneManutencao.setSelectedIndex(0);
        TamanhoColunaTable();
    }

    @Override
    public void CommitCampos() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    KeyAdapter pesquisaDados = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {

            switch (e.getKeyCode()) {
                case KeyEvent.VK_ENTER://Botão Enter
                    model.setNomeCampo(textFieldConsultar.getText());
                    model.setActionScript("P");
                    jTableConsulta.setModel(control.getDadosTableModel(model));
                    TamanhoColunaTable();
                    break;
            }
        }
    };

    @Override
    public void InicializarListener() {
        textFieldConsultar.addKeyListener(pesquisaDados);
        comboBoxProduto.addItemListener(comboBoxProdutoListener);
        comboBoxVersao.addItemListener(comboBoxVersaoListener);
        comboBoxCategoria.addItemListener(comboBoxCategoriaListener);
    }

    @Override
    public void Start() {
        Consultar();
        InicializarListener();
        CarregarDadosComboBox(model, null);
        setExtendedState(MAXIMIZED_BOTH);
        model.setNomeTela(getTitle());
        setFiltroCampo();
    }

    @Override
    public boolean ValidaCampos() {
        if (!UtilitariosCampos.getValidarCampos(jPanelManutencaoACadastro)) {
            tabbedPaneManutencao.setSelectedIndex(1);
            return false;
        } else if (!UtilitariosCampos.getValidarCampos(panelAbaBCadastro)) {
            tabbedPaneManutencao.setSelectedIndex(2);
            return false;
        } else if (!UtilitariosCampos.getValidarCampos(panelAbaCCadastro)) {
            tabbedPaneManutencao.setSelectedIndex(3);
            return false;
        } else {
            return true;
        }
    }

    @Override
    public void CarregarDadosComboBox(DocumentarModel model, String actionScript) {
        ProdutoController produtoControl = new ProdutoController();
        ProdutoModel produtoModel = produtoControl.getModel();
        produtoModel.setActionScript("C");
        comboBoxProduto.setModel(produtoControl.getDadosComboBoxModel(produtoModel));
    }

    @Override
    public void setFiltroCampo() {
        textFieldConsultar.setDocument(new setFiltroCampo(50, "LetraNumeroRealEspaco"));
        textFieldAba.setDocument(new setFiltroCampo(50, "LetraNumeroInteiroEspaco"));
        textFieldPosicao.setDocument(new setFiltroCampo(2, "NumeroInteiro"));
        textFieldCampo.setDocument(new setFiltroCampo(65535, "LetraNumeroInteiroEspaco"));
        textAreaFuncaoParametro.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
        textAreaExemplo.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
        textFieldImagemTela.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
        textFieldAnexo.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
        textFieldLinkVideo.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
        textAreaConsultaSQL.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
    }

}
